package com.fundamental.tools;

import java.util.*;

public class Test {

    static Map<Integer,Object> map = new HashMap<>();

    static List<Integer> list = new ArrayList<>();

    public static void main(String[] args){

        Random random = new Random();
        int avgTypes = 200;
        int loop = 100000;
        for(int i = 1;i <= avgTypes;i ++){
            map.put(i,new Object());
            list.add(i);
        }

        long before = System.nanoTime();

        for(int i = 0;i < loop; i ++){
            addToMapByLong(avgTypes);
            removeFromMapByLong(avgTypes);

            //addToListByLong(avgTypes);
            //removeFromListByLong(avgTypes);
        }

        long after = System.nanoTime();

        System.out.println(after - before);

    }

    static void addToMapByLong(int value){
        map.get(value);
        map.put(value,map.get(value));
    }

    static void removeFromMapByLong(int value){
        map.remove(value);
    }

    static void addToListByLong(int value){
        for(long l : list){
            if(l == value){
                return;
            }
        }
    }

    static void removeFromListByLong(int value){
        for(long l : list){
            if(l == value){
                return;
            }
        }
    }
}
